package com.CityHunter.Request;

import java.util.ArrayList;
import java.util.List;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;

import android.util.Log;

import com.CityHunter.Common.Http;


public class CreateGroupRequest {

	private String createGroupPage;

	public CreateGroupRequest(String createGroupPage) {
		this.createGroupPage = createGroupPage;
	}

	public int createGroup(int userid, String title,String description) {
		
		int result = 0;
		
		// Declare NameValuePair to store the data
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("userid", Integer
				.toString(userid)));
		params.add(new BasicNameValuePair("title", title));
		params.add(new BasicNameValuePair("description",
				description));

		// Send create group Request
		Http http = new Http();
		Log.d("cgrp_Debug", "Sending Request : " + createGroupPage);
		JSONArray jsonResponse = http.sendRequest(createGroupPage,
				params);
		try {
			result = Integer.parseInt(jsonResponse.getJSONObject(0)
					.getString("result"));
			Log.d("cgrp_Debug", "Response Result : " + result);
		} catch (Exception e) {
			Log.e("cgrp_Error", e.getMessage().toString());
		}

		return result;
	}

}
